import Mock from "mockjs";
const usersList=[
    {
        username:"admin",
        password:"123456",
        img:"http://pic.bizhi360.com/bpic/11/11311.jpg"
    },
    {
        username:"yichen",
        password:"123456",
        img:"http://pic.bizhi360.com/bpic/68/11268.jpg"
    },
    {
        username:"haolin",
        password:"123456",
        img:"http://pic.bizhi360.com/bpic/72/11272.jpg"
    },
    {
        username:"yushuai",
        password:"123456",
        img:"http://pic.bizhi360.com/bpic/39/11439.jpg"
    },
]

Mock.mock("/api/login","post",(option)=>{
    
    const {username,password}=JSON.parse(option.body);

    const arr=usersList.filter((item)=>item.username===username);
    if(arr.length===0){
        return{
            status:2,
            msg:"用户不存在"
        }
    }else{
        if(arr[0].password===password){
          const  result=arr[0]
            return{
                status:0,
                msg:"登录成功",
                result:result
            }
        }else{
          return{
            status:1,
            msg:"密码错误"
          } 
        }
    }
})

export default Mock
